package cn.kgc.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * Http 服务的初始化器  在初始化器中socketChannel中的pipeline中添加Handler
 * 让Handler处理客户端的Http请求
 */
public class HttpServerInitializer  extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        //一个channel对应一个pipeline一个pipeline对应多个handler
        socketChannel.pipeline()
                //处理编码和解码
                .addLast(new HttpServerCodec())
                //处理Http请求
                .addLast(new HttpServerHandler());
    }
}
